import Vue from 'vue'
import Vuex from 'vuex'
import cart from './cart'
import products from './products'

Vue.use(Vuex)
const myPlugin = store => {
  store.subscribe((mutation, state) => {
    console.log(mutation)
    if (mutation.type.startsWith('cart/')) {
      window.sessionStorage.setItem('cartdata', JSON.stringify(state.cart.cartproducts))
    }
  })
}
const store = new Vuex.Store({
  plugins: [myPlugin],
  state: {

  },
  mutations: {

  },
  getters: {

  },
  actions: {

  },
  modules: {
    products,
    cart
  }
})

export default store
